package com.hqyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.dao.KaoqingMapper;
import com.hqyj.pojo.Kaoqing;
import com.hqyj.service.IKaoqingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 考情表 服务实现类
 * </p>
 *
 * @author rock
 * @since 2021-11-18
 */
@Service
public class KaoqingServiceImpl extends ServiceImpl<KaoqingMapper, Kaoqing> implements IKaoqingService {

    @Autowired(required = false)
    KaoqingMapper kaoqingMapper;

    @Override
    public HashMap<String, Object> queryByUserIdAndDate(Integer sysId, String day) {
        HashMap<String, Object> map = new HashMap<>();
        //创建条件构造器
        QueryWrapper<Kaoqing> queryWrapper = new QueryWrapper<>();
        //定义查询条件
        queryWrapper.likeRight("times", day);
        queryWrapper.eq("sys_id", sysId);
        //查询
        List<Kaoqing> list = kaoqingMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            map.put("info", "您已经签到,请勿频繁点击!");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> add(Kaoqing kaoqing) {
        HashMap<String, Object> map = new HashMap<>();
        int i = kaoqingMapper.insert(kaoqing);
        if (i > 0) {
            map.put("info", "保存成功");
        } else {
            map.put("info", "保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> querySignOut(Integer sysId, String day, Integer kaoqingType) {
        HashMap<String, Object> map = new HashMap<>();
        //创建条件构造器
        QueryWrapper<Kaoqing> queryWrapper = new QueryWrapper<>();
        //定义查询条件
        queryWrapper.likeRight("times", day);
        queryWrapper.eq("sys_id", sysId);
        //查询,先查询用户是否签到
        List<Kaoqing> signIn = kaoqingMapper.selectList(queryWrapper);
        if (signIn.size() == 0) {
            map.put("info", "你还未签到，请先签到！");
        } else {
            queryWrapper.eq("kaoqing_type", kaoqingType);
            List<Kaoqing> list = kaoqingMapper.selectList(queryWrapper);
            if (list.size() > 0) {
                map.put("info", "您已经签退,请勿频繁点击!");
            }
        }
        return map;
    }
}
